package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.it.networkAssets.dict;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.networkassets.dict.ItNetworkAssetsDictField;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ItNetworkAssetsDictFieldRepo extends JpaRepository<ItNetworkAssetsDictField, Integer> {

    @Query(value = "select count(*) from t_gw_it_net_assets_dict_field " +
            "where deleted = 0 " +
            "and dict_code = :dictCode " +
            "and code = :fieldCode " +
            "and if ( :id is not null, id != :id , 1 = 1 ) " +
            "", nativeQuery = true)
    Integer countByFieldCodeAndIdNot(@Param("dictCode") String dictCode, @Param("fieldCode") String fileCode, @Param("id") Long id);


    List<ItNetworkAssetsDictField> findAllByDictCode(String dictCode);

    List<ItNetworkAssetsDictField> findAllByDictCodeIn(List<String> dictCode);

    void deleteAllByDictCodeIn(List<String> codeList);

    void deleteAllByIdIn(List<Long> delFieldCodeList);

    ItNetworkAssetsDictField findValueByDictCodeAndCode(String dictCode, String fieldCode);
}
